package com.remy.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import android.util.Log;


public class DBHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "1.db";
    public static final String TABLE_NAME1 = "position";
    public static final String TABLE_NAME2 = "orders";
    public static final int DATABASE_VERSION = 1;
    
    private String sql1 = "create table if not exists "+TABLE_NAME1+
    		" (_id integer primary key autoincrement," +
    		"description text," +
			"road text," +
			"lane varchar," +
			"road_number varchar," +
			"near_road_1 text," +
			"near_road_2 text," +
			"longitude float," +
			"latitude float," +
			"status integer);";
    
    private String sql2 = "create table if not exists "+TABLE_NAME2+
    		" (_id integer primary key autoincrement," +
    		"order_status varchar," +
    		"order_date text," +
    		"description text," +
			"road text," +
			"lane varchar," +
			"road_number varchar," +
			"near_road_1 text," +
			"near_road_2 text," +
			"order_operationId integer," +
			"order_car_number varchar);"; 
    

    public static final String TAG = "DBHelper";

    public DBHelper(Context context,String database_name,CursorFactory factory,int database_version) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	Log.e(TAG,"----------->onCreate");
		db.execSQL(sql1);
		db.execSQL(sql2);
		
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    	Log.e(TAG,"----------->onUpgrade");
        db.execSQL("drop table if exists" + TABLE_NAME1);
        db.execSQL("drop table if exists" + TABLE_NAME2);
        onCreate(db);
   }

}
